package ai_role_api

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"muziai-server/global"
	"muziai-server/models"
	"muziai-server/utils/res"
)

type AiRoleAvatarOrCategoryOptionsRequest struct {
	Type int8 `json:"type" form:"type" binding:"required,oneof=1 2"` // 1 avatar  2 category
}

func (AiRoleApi) AiRoleAvatarOrCategoryOptionsView(c *gin.Context) {

	var cr AiRoleAvatarOrCategoryOptionsRequest
	err := c.ShouldBindQuery(&cr)
	if err != nil {
		res.FailWithError(c, err)
		return
	}
	col := ""
	switch cr.Type {
	case 1:
		col = "avatar"
	case 2:
		col = "category"
	}

	var list []models.Options[string]
	global.DB.Model(models.AiRoleModel{}).Distinct(col).
		Where(fmt.Sprintf("%s <> ''", col)).
		Select(
			fmt.Sprintf("%s as label", col),
			fmt.Sprintf("%s as value", col)).Scan(&list)
	res.OkWithData(c, list)
}
